/*
 * Copyright 2002-2006 the original author or authors. Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License. You may obtain a copy of the License at
 * http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
 * either express or implied. See the License for the specific language governing permissions and limitations under the
 * License.
 */
package pikes.html.xhtml;

import java.util.LinkedList;
import java.util.List;

import pikes.util.Assert;
import pikes.xml.XMLTag;

/**
 * <code>&lt;div/&gt;</code> tag, see <a href="http://www.w3.org/TR/html401/struct/global.html#h-7.5.4">DIV element</a>
 * in HTML specification.
 * @author Peter Bona
 * @see <a href="http://www.w3.org/TR/html401/struct/global.html#h-7.5.4">The DIV element in HTML specification</a>
 */
public class Division extends NonRootTagFactory implements Block, CoreAttributes, I18N, Events, FlowList {

	private List<Flow> flows = new LinkedList<Flow>();

	@Override
	final protected CharSequence getTagName() {
		return "div";
	}

	public Division() {
		// left intentionally empty
	}

	public Division(Flow flow) {
		Assert.notNull(flow);
		add(flow);
	}

	public Division(CharSequence text) {
		this(new PCData(text));
	}

	public void add(Flow flow) {
		if (flow != null) {
			flows.add(flow);
		}
	}

	public void add(Block block) {
		if (block != null) {
			flows.add(block);
		}
	}

	public void add(Inline inline) {
		if (inline != null) {
			flows.add(inline);
		}
	}

	public void add(CharSequence text) {
		if (text != null) {
			add(new PCData(text));
		}
	}

	@Override
	protected void decorateCreatedTag(XMLTag tag) {

		for (Flow flow : flows) {
			flow.decorateTag(tag);
		}
	}
}
